<template>
  <!-- 设置估价货物详情 -->
    <el-dialog title="信息" :visible.sync="openGuaranteeValuationGoodsDetails" width="1200px" append-to-body :destroy-on-close="true" :before-close="beforeClose">
      <el-form ref="form" @submit.native.prevent :model="queryParams" :rules="rules" label-width="80px" :inline="true">
        <el-form-item label="条码" prop="bptm">
          <el-input
            v-model="queryParams.bptm"
            placeholder="请输入条码"
            clearable
             @keyup.enter.native="enterClick"
          />
        </el-form-item>
         <el-form-item label="柜号/批号" prop="spgh">
          <el-input
            v-model="queryParams.spgh"
            placeholder="请输入柜号/批号"
            clearable
             @keyup.enter.native="enterClick"
          />
        </el-form-item>
        <el-form-item label="入仓时间">
            <el-date-picker
              v-model="queryParams.ssrqid"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="选择日期"
              @change="handleQuery"
              >
            </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="质物清单序号" prop="spgh">
          <el-input
            placeholder="请输入质物清单序号"
            clearable
             @keyup.enter.native="enterClick"
          />
        </el-form-item> -->
        <el-form-item label="仓库" prop="spckmc">
          <el-input
            v-model="queryParams.spckmc"
            placeholder="请输入仓库"
            clearable
             @keyup.enter.native="enterClick"
          />
        </el-form-item>
          <el-form-item label="仓位" prop="ckcw">
          <el-input
            v-model="queryParams.ckcw"
            placeholder="请输入仓位"
            clearable
             @keyup.enter.native="enterClick"
          />
        </el-form-item>
        <el-form-item label="物品规格" prop="spzs">
          <el-input
            v-model="queryParams.spzs"
            placeholder="请输入物品规格"
            clearable
             @keyup.enter.native="enterClick"
          />
        </el-form-item>
        <el-form-item label="品牌" prop="spcd">
          <el-input
            v-model="queryParams.spcd"
            placeholder="请输入品牌"
            clearable
             @keyup.enter.native="enterClick"
          />
        </el-form-item>
        <el-form-item >
          <el-checkbox label="显示所有历史记录" v-model="queryParams.ally3" true-label="1" @change="getList"></el-checkbox>
          <el-checkbox label="未设置单价货物" v-model="queryParams.danjia0" true-label="1" @change="getList"></el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain size="mini" @click="handleGoodsDetailsExport" v-hasPermi="['zhcloud:hwdb:modify']">撤销担保</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button  type="primary" plain size="mini" @click="handleExport" v-hasPermi="['zhcloud:hwdb:export']">导出为Excel</el-button>
        </el-col>
      </el-row>
      <el-table
        :data="goodsDetails1List"
        row-key="spbhid"
         @selection-change="handleSelectionChange"
        show-summary
      >
        <af-table-column type="selection" width="50" align="center" />
        <af-table-column prop="zje" label="货物估值总价" fixed="left"></af-table-column>
        <af-table-column prop="jine" label="货物估值单价"></af-table-column>
        <af-table-column prop="sptm" label="用户条码"></af-table-column>
        <af-table-column prop="sptmc" label="仓库条码"></af-table-column>
        <af-table-column prop="spckmc" label="仓库"></af-table-column>
        <af-table-column prop="ckcw" label="仓位"></af-table-column>
        <af-table-column prop="spjs" label="件数"></af-table-column>
        <af-table-column prop="spjsl" label="单重(KG)"></af-table-column>
        <af-table-column prop="spsl" label="重量(吨)"></af-table-column>
        <af-table-column prop="spzs" label="物品规格"></af-table-column>
        <af-table-column prop="spcd" label="品牌"></af-table-column>
        <af-table-column prop="spgh" label="柜号"></af-table-column>
        <af-table-column prop="spbh" label="批号"></af-table-column>
        <af-table-column prop="allName" label="物品公司"></af-table-column>
        <af-table-column prop="ssrqid" label="入仓日期"></af-table-column>
        <af-table-column prop="ssrqid" label="质物清单序号"></af-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="pageNum"
        :limit.sync="pageSize"
        @pagination="goodsDetails1List"
      />
    </el-dialog>
</template>

<script>
import { listGoodsDetails1, valuationgoodsDetailsExport } from "@/api/storage/guarantee";

export default {
  name: "guaranteeGoodsDetails",
  data() {
    return {
      //行数据
      rowData:{},
      // 显示搜索条件
      showSearch: true,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      //弹窗状态
      openGuaranteeValuationGoodsDetails:false,
      // 查询参数
      queryParams: {
       	ally3: "",
        bptm: "",
        ckcw: "",
        danjia0: "",
        dbnum: "",
        isBa: "",
        khmcid: "",
        khpb: 0,
        shopId: 0,
        spcd: "",
        spckidis: [],
        spckmc: "",
        spgh: "",
        spzs: "",
        ssrqid: "",
        downloadType:"json"
      },
      //页数
      pageSize: 10,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
      //估价详情列表
      goodsDetails1List:[],
      //选择行数据
      goodsDetailsExportData:[]
    };
  },
  methods: {
    /**获取估价列表 */
    getList() {
      listGoodsDetails1(this.queryParams,{pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        this.goodsDetails1List = this.handleTree(response.rows, "spbhid");
        this.total = response.total;
      });
    },

    exportgoodsDetails() {
      valuationgoodsDetailsExport(this.goodsDetailsExportData).then(response => {
        this.$modal.msg('批量录出成功')
        this.getList()
      });
    },
    
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },

    /** 批量录出 */
    handleGoodsDetailsExport() {
      if(this.goodsDetailsExportData.length == 0) {
        return this.$modal.msg('请先选择录出数据!')
      }
      this.$modal.confirm('是否确认此操作？').then(() => {
        this.exportgoodsDetails();
      }).catch(() => {});
    },

    

    /** 导出为Excel */
    handleExport() {
      this.download('/storage/hwdb/export1', this.queryParams, `user_${new Date().getTime()}.xlsx`)
    },

     // 多选框选中数据
    handleSelectionChange(selection) {
      const selectionArr = []
      for(let i in selection) {
        selectionArr.push(selection[i].spbhid)
      }
      this.goodsDetailsExportData = selectionArr
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.queryParams = {
        ally3: "",
        bptm: "",
        ckcw: "",
        danjia0: "",
        dbnum: "",
        isBa: "",
        khmcid: this.queryParams.khmcid,
        khpb: 0,
        shopId: 0,
        spcd: "",
        spckidis: [],
        spckmc: "",
        spgh: "",
        spzs: "",
        ssrqid: "",
        downloadType:"json"
      };
      this.paramsAlly3Checkd = false
      this.resetForm("queryForm");
    },
    /**改变窗口状态 */
    changeGuaranteeValuationGoodsDetails() {
      this.openGuaranteeValuationGoodsDetails = !this.openGuaranteeValuationGoodsDetails;
    },
       /**enter键触发 */
    enterClick(e) {
      this.getList()
    },

    /**关闭弹窗 */
    beforeClose(done) {
      this.changeGuaranteeValuationGoodsDetails()
      this.reset()
      this.$emit('refresh', true)
      done()
    },
    /**打开弹窗 */
    open(id) {
      this.changeGuaranteeValuationGoodsDetails()
      this.queryParams.khmcid = id
      this.getList()
    }
  }
};
</script>
